<?php

namespace Addons\Zmphoto\Controller;

use Home\Controller\AddonsController;

class BaseController extends AddonsController {
	function _initialize() {
		parent::_initialize ();
		$controller = _CONTROLLER;
		$res ['title'] = '活动列表';
		$res ['url'] = addons_url ( 'Zmphoto://Zmphoto/lists' );
		$res ['class'] = ($controller == 'Zmphoto' && _ACTION == "lists") ? 'current' : '';
		$nav [] = $res;

		$res ['title'] = '数据列表';
		$res ['url'] = addons_url ( 'Zmphoto://PhoneData/lists' );
		$res ['class'] = ($controller == 'PhoneData' && _ACTION == "lists") ? 'current' : '';
		$nav [] = $res;

		$res ['title'] = '摄影者管理';
		$res ['url'] = addons_url ( 'Zmphoto://PhotoGl/lists' );
		$res ['class'] = ($controller == 'PhotoGl' && _ACTION == "lists") ? 'current' : '';
		$nav [] = $res;

		$res ['title'] = '活动数据统计';
		$res ['url'] = addons_url ( 'Zmphoto://Statistics/lists' );
		$res ['class'] = ($controller == 'Statistics' && _ACTION == "lists") ? 'current' : '';
		$nav [] = $res;

		$res ['title'] = '意见反馈';
		$res ['url'] = addons_url ( 'Zmphoto://InfoReview/lists' );
		$res ['class'] = ($controller == 'InfoReview' && _ACTION == "lists") ? 'current' : '';
		$nav [] = $res;
		
		$this->assign ( 'nav', $nav );

		define ( 'CUSTOM_TEMPLATE_PATH', ONETHINK_ADDON_PATH . 'Shop/View/default/Wap/Template' );
	}

	     /*生成二维码*/
    protected function createQRcode($save_path,$qr_data='PHP QR Code :)',$qr_level='L',$qr_size=4,$save_prefix='qrcode'){
        if(!isset($save_path)) return '';
        //设置生成png图片的路径
        $PNG_TEMP_DIR = & $save_path;
        //导入二维码核心程序
       vendor('phpqrcode.phpqrcode');
        //检测并创建生成文件夹
        if (!file_exists($PNG_TEMP_DIR)){
            mkdir($PNG_TEMP_DIR);
        }
        $filename = $PNG_TEMP_DIR.'test.png';
        $errorCorrectionLevel = 'L';
        if (isset($qr_level) && in_array($qr_level, array('L','M','Q','H'))){
            $errorCorrectionLevel = & $qr_level;
        }
        $matrixPointSize = 4;
        if (isset($qr_size)){
            $matrixPointSize = & min(max((int)$qr_size, 1), 10);
        }
        if (isset($qr_data)) {
            if (trim($qr_data) == ''){
                die('data cannot be empty!');
            }

            //生成文件名 文件路径+图片名字前缀+md5(名称)+.png
            $filename = $PNG_TEMP_DIR.$save_prefix.md5($qr_data.'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
            //开始生成
           \QRcode::png($qr_data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
        } else {
            //默认生成
            \QRcode::png('PHP QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2,true);
        }
        if(file_exists($PNG_TEMP_DIR.basename($filename)))
            return basename($filename);
        else
            return FALSE;
    }
}
